package com.leetcode.Offer;

import java.util.Arrays;

public class JZ03 {
    public int findRepeatNumber(int[] nums) {

        Arrays.sort(nums);
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                return nums[i];
            }
        }
        return -1;
    }
    public static int findRepeatNumber2(int[] nums) {

        for(int i=0; i<nums.length ;i++){

            while(nums[i]!=i){
                if(nums[nums[i]]!=nums[i]){
                    int tmp=nums[i];
                    nums[i]=nums[tmp];
                    nums[tmp]=tmp;
                }else{
                    return nums[i];
                }
            }

        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(findRepeatNumber2(new int[]{2, 3, 1, 0, 2, 5, 3}));
    }
}
